/*
 * @Autor: 张小鹏
 * @Date: 2020-04-17 16:37:14
 * @LastEditors: 张小鹏
 * @LastEditTime: 2020-04-26 16:12:06
 * @description: 
 */
function addleafToArray(array, leaf) {
    for (let item of array) {
        item.leaf=item.name == '全部'?true:leaf;
        item.type = item.name == '全部' ? 'all' : 'child';
    }
    return array;
}

function queryAreaList(resdata,code) {
    const AreaList = [];
    const traverse = function(data,code) {
    
        if(Array.isArray(data) && data.length>0)
        {
            console.log("queryAreaList",data)
            data.forEach((child) => {
                if (child.code==code) {
                    console.log("queryAreaList22",child.children)
                    if(Array.isArray(child.children) && child.children.length>0)
                    {
                        AreaList.push(...child.children)
                    }
                    //child.children
                 
                }
                traverse(child.children,code);
            });
        }
  
      
    };
    traverse(resdata,code);
    return AreaList;
  }

  function querylikeAreaList(resdata,code,level) {
    const AreaList = [];
    const traverse = function(data,code) {
        console.log("queryAreaList",data)
        if(Array.isArray(data) && data.length>0)
        {
            data.forEach((child) => {
                console.log("child***************",level);
         
                if(level>1)
                {
                    traverse(child.children,code);
                }
                else
                {
                    if (child.code.indexOf(code)>-1 || child.name.indexOf(code)>-1) {
                        AreaList.push(...child.children)
                    }
                }
               
            });
        }
  
      
    };
    traverse(resdata,code);
    return AreaList;
  }
export { addleafToArray,queryAreaList,querylikeAreaList }

